package org.njo.webapp.root.action.dts.generator.maintenance;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.njo.webapp.root.action.GenericAction;
import org.njo.webapp.root.model.activity.DTSActivity;
import org.njo.webapp.root.utility.ObjectExistsException;

public class NewMaintenanceAction extends GenericAction {

    // --------------------------------------------------------- Public Methods

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping  The ActionMapping used to select this instance
     * @param form     The optional ActionForm bean for this request (if any)
     * @param request  The HTTP request we are processing
     * @param response The HTTP response we are creating
     * @throws Exception if the application business logic throws
     *                   an exception
     */
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {
        DTSActivity dtsactivity = new DTSActivity();

//        String gen_name = request.getParameter("gen_name");
//        String gen_to_kind = request.getParameter("gen_to_kind");
//        String description = request.getParameter("description");
//        String[] field_set_physical_names = request.getParameterValues("field_set_physical_name");
//
//        // TODO 输入验证
//        
//        try {
//            Map<String, Object> yamlObject = new HashMap<String, Object>();
////            yamlObject.put("name", name);
////            yamlObject.put("type", type);
////            yamlObject.put("description", description);
//
//            yamlObject.put("gen_name", gen_name);
//            yamlObject.put("gen_to_kind", gen_to_kind);
//            yamlObject.put("description", description);
//            yamlObject.put("field_set_physical_names", field_set_physical_names);
//
//            dtsactivity.addSQLDDL(gen_name, yamlObject);
//        } catch (ObjectExistsException e) {
//            addMessage(request, new ActionMessage("dts.field.new.error.alreadyexist"));
//            return (new ActionForward("/dts.gt.sql.newddl.tiles", false));
//        }

        return (new ActionForward("/processor.dts.gt.listmaintenance.tiles", false));
    }

}